package View.Updata;

import Hander.Add.AddProjectAwardFormViewHandler;
import Hander.Updata.UpdataProjectAwardFormViewHandler;
import View.LeaderView;
import entity.Personnel;
import entity.ProjectAwardForm;
import service.PersonnelService;
import service.PersonnelServiceImpl;

import javax.swing.*;
import java.awt.*;
import java.sql.Date;
import java.util.Vector;

public class UpdataProjectAwardFormView extends JDialog {
    private String tableName="projectawardform";
    private JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));

    // 添加项目获奖信息
    JLabel projectIDLabel = new JLabel("ProjectID:", JLabel.RIGHT);
    JTextField projectIDTextField = new JTextField();
    JLabel certificateRankLabel = new JLabel("CertificateRank:", JLabel.RIGHT);
    JTextField certificateRankTextField = new JTextField();
    JLabel personnelIDLabel = new JLabel("PersonnelID:", JLabel.RIGHT);
    JTextField personnelIDTextField = new JTextField();
    JLabel approvalDateLabel = new JLabel("ApprovalDate:", JLabel.RIGHT);
    JTextField approvalDateTextField = new JTextField();

    JLabel AchievementIDLabel =new JLabel("AchievementID",JLabel.RIGHT);
    JTextField AchievementIDTextField =new JTextField();


    JButton updataBtn = new JButton("修改");
    UpdataProjectAwardFormViewHandler updataProjectAwardFormViewHandler;

    public UpdataProjectAwardFormView(LeaderView leaderView, int key) {
        super(leaderView, "修改项目获奖信息", true);

        PersonnelService personnelService=new PersonnelServiceImpl();
        Vector<Object> array = personnelService.getBy(key, "projectawardform");

//        setTableName(tableName);
        updataProjectAwardFormViewHandler = new UpdataProjectAwardFormViewHandler(this, leaderView);

        projectIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(projectIDLabel);
        projectIDTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(projectIDTextField);
        projectIDTextField.setText(""+array.get(0));
        certificateRankLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(certificateRankLabel);
        certificateRankTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(certificateRankTextField);
        certificateRankTextField.setText(""+array.get(1));
        personnelIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(personnelIDLabel);
        personnelIDTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(personnelIDTextField);
        personnelIDTextField.setText(""+array.get(2));

        approvalDateLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(approvalDateLabel);
        approvalDateTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(approvalDateTextField);
        approvalDateTextField.setText(""+array.get(3));

        AchievementIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(AchievementIDLabel);
        AchievementIDTextField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(AchievementIDTextField);
        AchievementIDTextField.setText(""+array.get(4));


        updataBtn.addActionListener(updataProjectAwardFormViewHandler);
        jPanel.add(updataBtn);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        setSize(400, 300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public ProjectAwardForm buildProjectAwardForm() {
        ProjectAwardForm projectAwardForm = new ProjectAwardForm();
        projectAwardForm.setProjectID(Integer.valueOf(projectIDTextField.getText()));
        projectAwardForm.setCertificateRank(Integer.valueOf(certificateRankTextField.getText()));
        projectAwardForm.setPersonnelID(Integer.valueOf(personnelIDTextField.getText()));
        projectAwardForm.setApprovalDate(Date.valueOf(approvalDateTextField.getText()));
        projectAwardForm.setAchievementID(Integer.valueOf(AchievementIDTextField.getText()));
        System.out.println("kanzheli1"+projectAwardForm.getAchievementID());
        return projectAwardForm;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
